package org.domain.sigepac.validator;

import java.lang.annotation.Annotation;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;

import org.hibernate.mapping.Property;
import org.hibernate.validator.PropertyConstraint;
import org.hibernate.validator.Validator;
import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("DataMinimaValidator")
public class DataMinimaValidator implements Validator, PropertyConstraint {

	private int anos;


	public boolean isValid(Object value) {
		Calendar data= Calendar.getInstance();
		data.setTime((Date) value);
		Calendar minimo=Calendar.getInstance();
		minimo.add(Calendar.YEAR, -anos);
		return data.before(minimo);
	}

	public void apply(Property arg0) {

	}

	public void initialize(Annotation parameters) {
		anos = ((DataMinima) parameters).anos();
	}
}